package com.mspbots.web.storage;

import lombok.extern.log4j.Log4j2;
import org.springframework.core.io.Resource;
import org.springframework.http.codec.multipart.FilePart;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.stream.Stream;

/**
 * com.mspbots.web.core.storage.FileSystemStorageService
 *
 * @author Alex bob(https://github.com/vnobo)
 * @date Created by 2019/9/20
 */
@Log4j2
@Service
public class FileSystemStorageServiceImpl implements StorageService {

    private final Path rootLocation;

    public FileSystemStorageServiceImpl(StorageProperties properties) {
        this.rootLocation = Paths.get(properties.getLocation());
    }

    @Override
    public void init() {
    }

    @Override
    public Mono store(String teamsUserId, Mono<FilePart> partMono) {
        String suffixName = ".jpg";
        String fileName = teamsUserId + suffixName;
        return partMono.flatMap(part -> part.transferTo(this.rootLocation.resolve(fileName)));
    }

    @Override
    public Stream<Path> loadAll() {
        return null;
    }

    @Override
    public Path load(String filename) {
        return null;
    }

    @Override
    public Resource loadAsResource(String filename) {
        return null;
    }

    @Override
    public void deleteAll() {

    }
}
